<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>常用地址</title>
		<link rel="stylesheet" type="text/css" href="../css/mui.min.css" />
		<link rel="stylesheet" type="text/css" href="../css/own.css" />
		<link rel="stylesheet" type="text/css" href="../css/iconfont.css" />

		<style type="text/css">
			.emptyAddress {
				text-align: center;
				margin-top: 50px;
				font-size: 0.9em;
			}
			
			h5 {
				color: black
			}
			
			.name {
				float: left;
			}
			
			.number {
				float: right;
			}
			
			.address {
				padding-top: 2px;
				clear: both;
			}
		</style>
	</head>

	<body>

		<div class="mui-content own-content-padding">
			<div class="emptyAddress own-left-nav-color">
				<span>空空如也</span>
				<br />
				<span>先添加一个收货地址吧</span>
				<br />

			</div>
			<div id="detailsMap">

				<div id="detailsMap-js">

				</div>

			</div>

			<div style="text-align: center;">
				<button id="addMap" type="button" class="add-bt"><span class="mui-icon mui-icon-plus"></span>&nbsp;添加服务对象地址</button>

			</div>

		</div>
		<script src="../js/mui.min.js" charset="UTF-8"></script>
		<script src="../js/own.js" charset="UTF-8"></script>
		<script type="text/javascript" charset="UTF-8">
			mui.init({
				swipeBack: true
			});
			var emptyAddress;
			var emptyAddressBtn;
			mui.plusReady(function() {

				//alert(plus.webview.currentWebview().id);

				window.addEventListener('refresh', function() {
					//alert(555);
					plus.webview.currentWebview().reload();
				});

				var data = {};
				data.tokenCode = plus.storage.getItem("tokenCode");
				data.accountId = plus.storage.getItem("accountId");

				mui.ajax(url + 'rest/searchAccount', {

					data: data,

					dataType: 'json', //服务器返回json格式数据

					type: 'POST', //HTTP请求类型

					timeout: 10000, //超时时间设置为10秒；

					//headers:{'Content-Type':'application/json'},	              

					success: function(result) {

						if(result.status != '0') {
							mui.alert("查询地址信息错误");

						} else {

							//document.getElementById("detailsMap").innerHTML=userAddrList;

							//alert(userAddrList);
							var htmlStr = '<ul id="addressList" class="mui-table-view">';

							var obj = result.data.userAddresses;

							for(var i = 0; i < obj.length; i++) {
								//alert(obj[i].name);
								//alert(obj[i].phone);

								htmlStr += ' <li class="mui-table-view-cell">'
								htmlStr += '<h5 class="addressId" hidden="hidden">' + obj[i].addressId + '</h5>';
								htmlStr += '<h5 class="name">' + obj[i].name + '</h5>';
								htmlStr += '<h5 class="number">' + obj[i].phone + '</h5>';
								htmlStr += '<p class="address mui-ellipsis-2">' + obj[i].province + " " + obj[i].city + " " +obj[i].area+" " + '<span id=back-detail>' + obj[i].address + '</sapn>' + '</p>';
								htmlStr += '<p class="dizhi1" hidden="hidden">' + obj[i].province + '</p>';
								htmlStr += '<p class="dizhi2" hidden="hidden">' + obj[i].city + '</p>';
								htmlStr += '<p class="dizhi3" hidden="hidden">' + obj[i].area + '</p>';
								htmlStr += '<p class="dizhi4" hidden="hidden">' + obj[i].address + '</p>';
								htmlStr += '</li>';

							}
							htmlStr += '</ul>';
							document.getElementById("detailsMap-js").innerHTML = htmlStr;

							emptyAddress = document.querySelector('.emptyAddress');
							emptyAddressBtn = emptyAddress.querySelector('button');
							//判断如果没有可用地址就显示添加
							if(false) {
								emptyAddress.style.display = 'block';
								emptyAddressBtn.addEventListener('tap', function() {
									showaddressWeb();
								}, false);
							} else {
								emptyAddress.style.display = 'none';
							}
							//地址修改点击事件
							mui('.mui-table-view').on('tap', '.mui-table-view-cell',
								function() {

									//alert(this.getElementsByClassName("addressId")[0].innerHTML);
									var addressId = this.getElementsByClassName("addressId")[0].innerHTML;
									var name = this.getElementsByClassName("name")[0].innerHTML;
									var phoneNum = this.getElementsByClassName("number")[0].innerHTML;

									var address = this.getElementsByClassName("address")[0].innerHTML;
									var dizhi1 = this.getElementsByClassName("dizhi1")[0].innerHTML;
									var dizhi2 = this.getElementsByClassName("dizhi2")[0].innerHTML;
									var dizhi3 = this.getElementsByClassName("dizhi3")[0].innerHTML;
									var dizhi4 = this.getElementsByClassName("dizhi4")[0].innerHTML;

									/*plus.storage.setItem("myAddressId",addressId);
									plus.storage.setItem("myOrderName",name);
									plus.storage.setItem("myOrderPhone",phoneNum);
									plus.storage.setItem("myOrderAddr",address);*/
									//alert(addressId);alert(name);alert(phoneNum);alert(address);
									//showaddressWeb();
									mui.openWindow({
										url: 'address-needtem.html',
										id: 'address-needtem.html',
										extras: {

											name: name,
											phoneNum: phoneNum,
											address: address,
											addressId: addressId,
											dizhi1: dizhi1,
											dizhi2: dizhi2,
											dizhi3: dizhi3,
											dizhi4: dizhi4

										}
									});

								});
						}
					},

					error: function(xhr, type, errorThrown) {

						//异常处理；

						mui.alert("查询地址信息异常")

					}
				});

				//接收rightbar事件
				/*window.addEventListener('navRightPress', function() {
					showaddressWeb();
				}, false);*/
				var addmap = document.getElementById("addMap");
				addmap.addEventListener('tap', function() {
					//var cell = this;
					mui.openWindow({
						url: 'add-address.html',
						id: 'add-address.html',
					});

				});

			});
		</script>

	</body>

</html>